package com.sumansoul.slidingdeletedemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    RecyclerView rv_list;
    private List<LoginBean>  list = new ArrayList<>();
    private  MyListAdapter myListAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rv_list = (RecyclerView) findViewById(R.id.rv_list);
        init();
    }


    /**
     * 初始化数据
     */
    private void init() {

        try {
            for (int i=1;i<21;i++){
                list.add(new LoginBean("第"+i+"条数据"));
            }

            if (myListAdapter==null){
                rv_list.setLayoutManager(new LinearLayoutManager(this));
                rv_list.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));

                myListAdapter = new MyListAdapter(R.layout.sample_slidingview,list);
                rv_list.setAdapter(myListAdapter);
            }else {
                myListAdapter.notifyDataSetChanged();
            }

            myListAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (view.getId()){
                        case R.id.tv_delete:
                            list.remove(position);
                            myListAdapter.notifyDataSetChanged();
                            Log.d("LUO","===删除==");
                            break;
                        case R.id.tv_cancel:
                           // SlidingDeleteView  slidingDeleteView = (SlidingDeleteView) adapter.getViewByPosition(rv_list, position, R.id.slidingview);
                            //slidingDeleteView.setDeleteViewGone();
                           // myListAdapter.notifyItemChanged(position);
                            myListAdapter.notifyDataSetChanged();
                            Log.d("LUO","===隐藏==");
                            break;
                        default:
                            break;
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
